import { http } from './request'

export async function getUserInfo() {
  try {
    const response = await http.get('/api/me')
    return response.data
  } catch (error) {
    console.error('获取用户信息失败:', error)
    throw error
  }
}
export async function getConversations(page = 1) {
  try {
    const response = await http.get('/api/conversations?page=' + page)
    return response.data
  } catch (error) {
    console.error('获取用户信息失败:', error)
    throw error
  }
}

export async function getConversationsDetail(data) {
  try {
    const response = await http.get(
      `/api/conversations/${data.id}?with_messages=true&page=${data.page}`,
    )
    return response.data
  } catch (error) {
    console.error('获取用户信息失败:', error)
    throw error
  }
}

export async function getAlerts(page = 1) {
  try {
    const response = await http.get('/api/alerts?page=' + page)
    return response.data
  } catch (error) {
    console.error('获取用户信息失败:', error)
    throw error
  }
}

//获取怀旧服讯息版块
export async function getRebornThreadList(page = 1) {
  try {
    const response = await http.get('/api/search-forums/65/threads?page=' + page)
    return response.data
  } catch (error) {
    console.error('获取用户信息失败:', error)
    throw error
  }
}

//查看帖子详情
export async function getThreadDetail(threadId, data) {
  try {
    let url = `/api/threads/${threadId}`
    if (data && Object.keys(data).length > 0) {
      const params = new URLSearchParams(data).toString()
      url += `?${params}`
    }
    const response = await http.get(url)
    return response.data
  } catch (error) {
    console.error('获取用户信息失败:', error)
    throw error
  }
}
